// 1.准备vuex的模块
import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: constantRoutes
}

const mutations = {
  setRoutes(state, filterRoutes) {
    state.routes = [...constantRoutes, ...filterRoutes]
  },
  removeRoutes(state) {
    state.routes = constantRoutes
  }
}

const actions = {
  // 2.定义过滤路由的action
  filterRouter(ctx, menus) {
    const filterRoutes = asyncRoutes.filter(t => menus.includes(t.children[0].name))
    ctx.commit('setRoutes', filterRoutes)
    return filterRoutes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

